package com.zx.sms.codec.cmpp;

import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import org.junit.Assert;
import org.junit.Test;

import com.zx.sms.codec.AbstractTestMessageCodec;
import com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage;
import com.zx.sms.connect.manager.TestConstants;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

public class TestDiffrentMsgFmt extends AbstractTestMessageCodec<CmppSubmitRequestMessage>{

	String expect = TestConstants.testSmsContent;
	
	/**
	 * 部分客户发送的长短信各个片断的msgfmt不相同。要先根据各自片断的字符编码转码后再合并长短信。
	 * 
	 */
	@Test
	public void testDecode() throws DecoderException
	{
		byte[]  data = Hex.decodeHex("0000012b0000000455c51d4e43c0ee40261c1d50040100093130303836000000000002000000000000000000000000000000000000000000000108000000000000303130303030303000000000000000000000000000000000000000000000000000000000000000000000313030383600000000000000000000000000000000013133383030313338303030000000000000000000008c050003e404015c0a656c76845ba26237002c60a8597dff0160a84e8e0032003000310036002d00300033002d00320033002000310034003a00350031003a00330036901a8fc74e2d56fd79fb52a8003100300030003800359500552e4e137ebf8ba28d2d768430104e0052a0624b673a9ad86e059632522e4fdd62a4819c3011ff0c8bf770b951fb652f4ed800000000000000000000012b0000000455c51d5143c0ee40261c1d50040200093130303836000000000002000000000000000000000000000000000000000000000108000000000000303130303030303000000000000000000000000000000000000000000000000000000000000000000000313030383600000000000000000000000000000000013133383030313338303030000000000000000000008c050003e404020068007400740070003a002f002f007700770077002e00310030003000380035002e0063006e002f00770065006200380035002f0070006100670065002f007a0079007a0078007000610079002f007700610070005f006f0072006400650072002e00680074006d006c003f006f007200640065007200490064003d0037003600440045004600000000000000000000012b0000000455c51d5243c0ee40261c1d50040300093130303836000000000002000000000000000000000000000000000000000000000108000000000000303130303030303000000000000000000000000000000000000000000000000000000000000000000000313030383600000000000000000000000000000000013133383030313338303030000000000000000000008c050003e40403003900410045003100380030003800460035003000360046004400340045003600430042003700380032004500330042003800450037004500450038003700350045003700360036004400330044003300330035004300205b8c62104e0b535530028bf75728003600305206949f51855b8c6210652f4ed8ff0c59826709759195eeff0c8bf70000000000000000000000ad0000000455c51d5343c0ee40261c1d50040400093130303836000000000002000000000000000000000000000000000000000000000100000000000000303130303030303000000000000000000000000000000000000000000000000000000000000000000000313030383600000000000000000000000000000000013133383030313338303030000000000000000000000e050003e4040461626331303038350000000000000000".toCharArray());
		
		ByteBuf buf = Unpooled.wrappedBuffer(data);
		ch.writeInbound(buf);
		CmppSubmitRequestMessage result = null;
		boolean success = false;
		while(null!= ( result =  (CmppSubmitRequestMessage)ch.readInbound())){
			
			Assert.assertNotNull(result);
			System.out.println(result.getMsgContent());
			success = true;
		}
		Assert.assertTrue(success);
		
	}
	
}
